package com.kyoto.administrator.mvpdemo.mvp.model;

import android.text.TextUtils;

import com.kyoto.administrator.mvpdemo.OnLoginFinishedListener;
import com.kyoto.administrator.mvpdemo.baselib.retroft.http.RetrofitFactory;
import com.kyoto.administrator.mvpdemo.baselib.retroft.http.base.BaseObserver;
import com.kyoto.administrator.mvpdemo.baselib.retroft.http.bean.BaseEntity;
import com.kyoto.administrator.mvpdemo.net.Request;

public class LoginImpl extends Request implements ILoginInfo {

    @Override
    public void login(final String username, final String password, final OnLoginFinishedListener listener) {
        if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)){
            RetrofitFactory.getInstence().API()
                    .login(username,password)
                    .compose(this.<BaseEntity<LoginBean>>setThread())
                    .subscribe(new BaseObserver<LoginBean>() {
                        @Override
                        protected void onSuccees(BaseEntity<LoginBean> t) throws Exception {
                            listener.onSuccess();
                        }

                        @Override
                        protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                            listener.onUsernameError();
                        }
                    });
        }
    }
}